home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1997 #3
/
Amiga Plus CD - 1997 - No. 03.iso
/
pd
/
programmierung
/
alienbreed3d2_src
/
amos
/
compactobj.amos
/
compactobj.amosSourceCode
< prev
Wrap
AMOS Source Code
|
1997-01-31
|
5KB
|
274 lines
Set Buffer 80
Screen Open 7,640,24,2,Hires : Wait Vbl : Curs Off : Flash Off : Extension_12_0380 -1
Palette $8,$FF0 : Paper 0 : Pen 1 : Ink 1 : Box 0,4 To 639,20
Global HF,WF
Dim U(128*30),T(128*30),B(128*30)
1
For A=0 To 64*30 : U(A)=0 : Next
Screen Open 0,320,256,4,Lowres
Curs Off : Flash Off : Cls 0
Colour 1,$F00
Colour 2,$FFF
Colour 3,$F0
Ink 2 : Box 0,16 To 319,24
Ink 1
Pen 2 : Paper 0
Erase 12
Trap Pload "ab3:includes/findsame.inc",12
If Errtrap
Screen To Front 7 : Screen 7
Locate 1,1 : Print Space$(78)
Locate 1,1 : Centre "Unable to load 'ab3:includes/findsame.inc'"
Wait Key
Edit
End If
Erase 15
Reserve As Work 15,640*640+12
F$=Fsel$("ab3:includes/","","Filename: ")
F$=F$-".dat"
F$=F$-".pal"
F$=F$-".wad"
F$=F$-".ptr"
Erase 14
Erase 13
Erase 11
Erase 10
If F$="" : Edit : End If
Trap Bload F$+".dat",Start(15)
If Errtrap
Screen To Front 7 : Screen 7
Locate 1,1 : Print Space$(78)
Locate 1,1 : Centre "Unable to load '"+F$+".dat'"
Wait Key
Edit
End If
NF=Deek(Start(15))
WF=Deek(Start(15)+2)
HF=Deek(Start(15)+4)
S=Start(15)+6
For A=4 To WF*HF*NF Step 4
Loke S-6,Leek(S) : Add S,4
Next
TL=WF*NF
Reserve As Work 14,WF*HF*NF
Reserve As Work 13,WF*NF*4
Reserve As Work 11,WF*NF*4
Reserve As Work 10,WF*NF*4
Global S,F,D
S=TL
D=NF*WF*HF
'Goto NOELIM
Curs Off
Locate 0,0 : Print "Eliminating repeated strips..."
NS=1
F=Start(15)+HF
D=HF
For X=1 To S-1
Loke Start(12),Start(15)
Loke Start(12)+4,Start(15)+D-HF
Loke Start(12)+8,F
Doke Start(12)+12,HF
Call Start(12)+14
P=Leek(Start(12))
If P=-1
Loke Start(13)+X*4,D/HF
For A=0 To HF-4 Step 4 : Loke Start(15)+D+A,Leek(F+A) : Next : Add NS,1
Add D,HF
Else
Loke Start(13)+X*4,P/HF
End If
Locate 0,1
Print "Bytes Saved:";(F-Start(15))-D;" "
H=(X*318)/S+1
Ink 1
Extension_12_04CC H,17 To H,23
H=(NS*318)/S+1
Ink 3
Extension_12_04CC H,17 To H,23
Add F,HF
Next
'
S=NS
NOELIM:
D=D+Start(14)
'Goto NOORD
'
U(0)=1
Cls 0
Ink 2 : Box 0,16 To 319,24
Ink 1
Pen 2 : Paper 0
Locate 0,0 : Print "Sorting strips into most efficient order..."
F=Start(15)
For A=0 To S-1
FINDTOP[F]
T(A)=Param
FINDBOT[F]
B(A)=Param
Add F,HF
Next
F=Start(15) : D=Start(14)
E=Start(15)+(S-1)*HF
B=HF-B(0)
For A=0 To HF-1 : Poke D,Peek(F) : Add D,1 : Add F,1 : Next
'
TD=0
For X=1 To S-1
DIFF=200
AD=0
N=0
For J=Start(15) To E Step HF
If U(N)=0
T=Abs(T(N)-B)
If T<DIFF
DIFF=T : AD=J : NU=N
End If
If T=0
J=E
End If
End If
Add N,1
Next
U(NU)=1
For A=0 To HF-4 Step 4
Loke D+A,Leek(AD+A)
Next
Loke Start(11)+NU*4,(D-Start(14))/HF
H=(X*318)/S+1
Ink 3
Extension_12_04CC H,17 To H,23
B=HF-B(NU)
Add D,HF
Next
'
NOORD:
'Goto NOPACK
Cls 0
TD=0
Ink 2 : Box 0,16 To 319,24
Ink 1
Pen 2 : Paper 0
Locate 0,0 : Print "Packing Strips..."
F=Start(14) : D=Start(14)+HF
For A=0 To HF-1 : Poke Start(14)+A,Peek(Start(15)+A) : Next
FINDBOT[F] : Add F,HF
B=Param
For X=1 To S-1
FINDTOP[F]
T=Param
J=HF-B
K=Min(J,T)
TD=TD+Abs(J-T)
D=D-K
FINDBOT[F] : B=Param
For A=0 To HF-1 : Poke D+A,Peek(F+A) : Next
Loke Start(10)+X*4,D-Start(14)
Add D,HF
Add F,HF
Locate 0,1
Print "Bytes Saved:";(F-D);" "
H=(X*318)/S+1
Ink 1
Extension_12_04CC H,17 To H,23
H=(((D-Start(14))/HF)*318)/S+1
Ink 3
Extension_12_04CC H,17 To H,23
H=((TD/HF)*318)/S+1
Ink 0
Extension_12_04CC H,17 To H,23
Next
'
NOPACK:
MD=D-Start(14)
'
For A=0 To TL-1
P=Leek(Start(13)+A*4)
P=Leek(Start(11)+P*4)
P=Leek(Start(10)+P*4)
Loke Start(13)+A*4,P
Next
'
LF=MD
LF=LF/3
LF=LF+64
For A=0 To TL-1
P=Leek(Start(13)+A*4)
If P<=LF and(P+HF)>LF
FT=P
End If
If(P<=(LF+LF)) and((P+HF)>(LF+LF))
ST=P
End If
' If(P<=MD) and((P+HF)>MD)
' MD=P+HF
' End If
Next
D=Start(15) : F=Start(14)
For A=0 To MD
Poke Start(15)+A,0
Next
For A=0 To FT+HF-1
Doke D,Peek(F) : Add D,2 : Add F,1
Next
F=F-HF
BIGD=D
D=Start(15)
For A=FT To ST+HF-1
C=Deek(D)
C=C+(Peek(F)*32)
Doke D,C
Add D,2 : Add F,1
Next
BIGD=Max(BIGD,D)
F=F-HF
D=Start(15)
For A=ST To MD+HF-1
C=Deek(D)
C=C+(Peek(F)*32*32)
Doke D,C
Add D,2 : Add F,1
Next
BIGD=Max(BIGD,D)
For A=0 To TL-1
P=Leek(Start(13)+A*4)
If P>=ST
P=P-ST
P=P*2
P=P+$2000000
Else
If P>=FT
P=P-FT
P=P*2
P=P+$1000000
Else
P=P*2
End If
End If
Loke(Start(13)+A*4),P
Next
'
Locate 0,4
Print "Old File Size:";TL*HF
ZLF=(BIGD-Start(15))+4*TL
Print "New File Size:";ZLF
Print "Memory saving:";(TL*HF)-ZLF;" = ";((TL*HF-ZLF)*100)/(TL*HF);"%"
Bsave F$+".wad",Start(15) To BIGD
Bsave F$+".ptr",Start(13) To Start(13)+TL*4
Wait Key
Goto 1
'
Procedure FINDBOT[A]
Z=HF
For L=HF-1 To 0 Step -1 : If Peek(A+L)=0 Then Z=L Else L=-10
Next
End Proc[Z]
'
Procedure FINDTOP[A]
Z=0
For L=0 To HF : If Peek(A+L)=0 Then Z=L+1 Else L=1000
Next
End Proc[Z]